#!/bin/bash
#source ~/.bash_profile
#export JAVA_HOME=/usr/local/jdk/jdk1.8.0_131
#export PATH=$JAVA_HOME/bin:$PATH
#export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

source /etc/profile
export JAVA_OPTIONS="-XX:+HeapDumpOnOutOfMemoryError  -XX:HeapDumpPath=/root/project/dump/"

workdir=$(cd $(dirname $0); pwd)
echo "当前路径是：${workdir}"
files=`ls ${workdir} | grep -i .jar | grep -v old.jar`
for file in ${files}
do	
echo ${file}
PID=`ps ux | grep -i ${file}| grep -v "grep" |  awk {'print $2'}`
echo "=================当前服务进程是：'$PID',准备关闭进程=========="
kill -9 $PID
echo "=================当前进程'$PID'已关闭，准备启动新服务========="
nohup java -jar  -Dloader.path=${workdir}/lib   $JAVA_OPTIONS  $file >run.log 2>&1 &
echo "================='$file'服务启动完毕====================="
done
		tail -f run.log